package marchsoft.modules.tiku.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import marchsoft.modules.tiku.entity.ERepository;
import marchsoft.base.BasicMapper;
import marchsoft.modules.tiku.entity.dto.ERepositoryDto;
import marchsoft.modules.tiku.entity.dto.SelectRepositoryDto;
import marchsoft.modules.tiku.entity.excel.RepositoryExcel;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
* <p>
* 题库 Mapper 接口
* </p>
*
* @author zsy
* @since 2022-03-29
*/
@Component
public interface ERepositoryMapper extends BasicMapper<ERepository> {

    /**
     * 按条件联表查询
     * */
    @Select("select er.id,st.name as typeName,ques_type,ques_content,safe_type_id," +
            "options,answer,er.create_time,er.create_time " +
            "from e_repository er  " +
            "LEFT JOIN e_safe_type st on er.safe_type_id=st.id " +
            "${ew.customSqlSegment}  ")
    IPage<SelectRepositoryDto> getAll(IPage<Object> page, @Param(Constants.WRAPPER) QueryWrapper<Object> query);

//    @Insert(
//            "<script>" +
//                    "insert into e_repository (id,safe_type_id,ques_type,ques_content, " +
//                    "options,answer,is_check,create_time,update_time,create_by,update_by,is_deleted) " +
//                    "values " +
//                    "<foreach collection= 'list' item= 'item' open= '(' separator= ',' close=')' > " +
//                    "null,#{item.safeTypeId},#{item.quesType},#{item.quesContent},#{item.options},#{item.answer}," +
//                    "0,now(),now(),1,1,0"+
//                    "</foreach> " +
//                    "</script>"
//    )
//    void save(@Param("list") List<RepositoryExcel> cachedDataList);

    @Select("SELECT * FROM e_repository WHERE safe_type_id=#{id} ")
    IPage<ERepository> getBySafeTypeId(IPage<Object> page,@Param("id") Long id);

    @Select("SELECT * FROM e_repository  ${ew.customSqlSegment}")
    IPage<ERepositoryDto> selectRepositoryPage(IPage<Object> page,@Param(Constants.WRAPPER) LambdaQueryWrapper<ERepository> queryWrapper);
}
